<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');
require_once JPATH_COMPONENT.DS.'/helpers/functions.check.php';

/**
 * HTML View class for the eventcalendar component
 */
class EventcalendarViewGeorss extends JView {
	function display($tpl = null) {
		
		//Todo: johonkin järkevämpään paikkaan
		$default_limit = 10;
	

		$alkuaika = JRequest::getVar( 'alkuaika' );	
		if($alkuaika == null)
		{			
			date_default_timezone_set('Europe/Helsinki');
			$alkuaika = date('d.m.Y');
		}
		
		//Monta haetaan
		$limit = JRequest::getVar( 'limit', '' );

		//Oma model
		$model = &$this->getModel();
		
		$events = $model->getEvents($alkuaika, $limit);	
		/*if(intval($limit) > 0)
		{
			$events = $model->getEvents($alkuaika, $limit);
		}
		else 
		{
			$events = $model->getEvents($alkuaika, $default_limit);
		}
		*/
		
		


		//	Geolokaatiot tapahtumille
		foreach ($events as $event)
		{
			if($event->position_id)
			{
				$position 	= $model->getPosition($event->position_id);
				$event->lat = $position[0]->dpposition_lat;
				$event->lon = $position[0]->dpposition_lon;		
			}
		}

			

		//$events =& $this->get('events');	
		$this->assignRef('events',$events);
		
				
		$itemid= JRequest::getVar( 'itemid' );
		
		
		$modemodel = &$this->getModel('moderator');
		$kalenteri = $modemodel->getCalendar(getCurrentCalendar($itemid));
		$this->assignRef('kalenteri',$kalenteri);
		//print_r($kalenteri);
		//sexit;
		
		
		
		parent::display($tpl);
	}

	
}
?>
